<template>
  <div>
    <v-viewer ref="view"></v-viewer>
    <template v-if="orderInfo.sufProcessType == 3">
      <fast-loan :order-info="orderInfo"
                 :is-info="isInfo"
                 @show="showImg"></fast-loan>
    </template>
    <template v-else>
      <order-base :order-info="orderInfo"></order-base>
      <div v-if="orderInfo.examineType == 2"
           class="customer-area">
        <div class="title">
          <div class="point"></div>
          <span>初审审核</span>
          <el-button @click="down(1)"
                     style="margin-left:50px;"
                     type="primary"
                     size="small">资料下载</el-button>
        </div>
        <order-data :data-info.sync="firstInfo"
                    :order-info="orderInfo"
                    :is-info="isInfo"
                    @show="showImg"></order-data>
      </div>
      <div v-if="orderInfo.status > 30 && orderInfo.status != 150 && orderInfo.businessType == 2"
           class="customer-area">
        <div class="title">
          <div class="point"></div>
          <span>车辆评估审核</span>
          <el-button @click="down(5)"
                     style="margin-left:50px;"
                     type="primary"
                     size="small">资料下载</el-button>
        </div>
        <order-data :data-info.sync="assessInfo"
                    :order-info="orderInfo"
                    :is-info="isInfo"
                    @show="showImg"></order-data>
      </div>
      <div v-if="orderInfo.status > 30 && orderInfo.status < 150"
           class="customer-area">
        <div class="title">
          <div class="point"></div>
          <span>终审审核</span>
          <el-button @click="down(2)"
                     style="margin-left:50px;"
                     type="primary"
                     size="small">资料下载</el-button>
        </div>
        <template v-if="orderInfo.businessType < 3 && (loanAfterInfo && loanAfterInfo.some(a => a.attrId === 28))">
          <el-form size="medium"
                   label-position="right"
                   label-width="110px">
            <file-pic-up label-name="合同模板"
                         file-name="合同模板"
                         :product-name="orderInfo.orderId + ''"
                         :pic-url-list.sync="orderInfo.contractFileList"
                         :file-path.sync="orderInfo.contractFile"
                         :example-loop.sync="orderInfo.contractFileLoop"
                         @show="showImg"></file-pic-up>
          </el-form>
        </template>
        <el-row v-if="orderInfo.contractFile"
                :gutter="10">
          <el-col :span="3">
            <div class="content-title">
              <span>合同模板</span>
            </div>
          </el-col>
          <el-col :span="19">
            <el-col>
              <span>{{ orderInfo.contractFileList?orderInfo.contractFileList[0].name:null }}</span>
              <a :href="orderInfo.contractFile"
                 target="_blank">下载</a>
            </el-col>
            <el-col v-if="orderInfo.contractFileLoop && orderInfo.contractFileLoop.length > 0">
              <el-col :span="3"
                      v-for="(item, key) in orderInfo.contractFileLoop"
                      :key="key">
                <pic-view :pic-url-list.sync="item.urls"
                          upload-class="short-upload"
                          :pic-name-list.sync="item.names"
                          :max-size="1"
                          @showImg="showImg"></pic-view>
                <div class="stalker">
                  <span>{{ item.display }}</span>
                </div>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <order-data :data-info.sync="lastInfo"
                    :order-info="orderInfo"
                    :is-info="isInfo"
                    @show="showImg"></order-data>
      </div>
      <div v-if="(orderInfo.status > 60 && orderInfo.status < 150 || orderInfo.status == 50) && orderInfo.businessType < 3 && orderInfo.sufProcessType == 1"
           class="customer-area">
        <div class="title">
          <div class="point"></div>
          <span>放款材料</span>
          <el-button @click="down(3)"
                     style="margin-left:50px;"
                     type="primary"
                     size="small">资料下载</el-button>
        </div>
        <order-data :data-info.sync="loanAfterInfo"
                    :order-info="orderInfo"
                    :is-info="isInfo"
                    @show="showImg"></order-data>
        <el-row :gutter="10">
          <el-col :span="3">
            <div class="content-title">
              <span>收款确认函</span>
            </div>
          </el-col>
          <el-col :span="19">
            <div>
              <pic-view :pic-url-list.sync="orderInfo.receivables.urls"
                        upload-class="lang-upload"
                        :pic-name-list.sync="orderInfo.receivables.names"
                        :upload-data="{ picName: 'customer\\' + orderInfo.customerId }"
                        :upload-type="isInfo"
                        @showImg="showImg"></pic-view>
            </div>
          </el-col>
        </el-row>
      </div>
      <div v-if="((orderInfo.status > 100 && orderInfo.status < 150) || orderInfo.status == 70 ) && orderInfo.businessType < 3 && orderInfo.sufProcessType == 1"
           class="customer-area">
        <div class="title">
          <div class="point"></div>
          <span>抵押材料</span>
          <el-button @click="down(4)"
                     style="margin-left:50px;"
                     type="primary"
                     size="small">资料下载</el-button>
        </div>
        <order-data :data-info.sync="mortgageInfo"
                    :order-info="orderInfo"
                    :is-info="isInfo"
                    @show="showImg"></order-data>
      </div>
      <div v-if="(orderInfo.status == 90 || orderInfo.status == 70 || orderInfo.status == 100 || orderInfo.status == 130) && orderInfo.businessType < 3 && orderInfo.sufProcessType == 2"
           class="customer-area">
        <div class="title">
          <div class="point"></div>
          <span>抵押放款材料</span>
          <el-button @click="down(99)"
                     style="margin-left:50px;"
                     type="primary"
                     size="small">资料下载</el-button>
        </div>
        <order-data :data-info.sync="loanAfterInfo"
                    :order-info="orderInfo"
                    :is-info="isInfo"
                    @show="showImg"></order-data>
        <el-row :gutter="10">
          <el-col :span="3">
            <div class="content-title">
              <span>收款确认函</span>
            </div>
          </el-col>
          <el-col :span="19">
            <div>
              <pic-view :pic-url-list.sync="orderInfo.receivables.urls"
                        upload-class="lang-upload"
                        :pic-name-list.sync="orderInfo.receivables.names"
                        :upload-data="{ picName: 'customer\\' + orderInfo.customerId }"
                        :upload-type="isInfo"
                        @showImg="showImg"></pic-view>
            </div>
          </el-col>
        </el-row>
        <order-data :data-info.sync="mortgageInfo"
                    :order-info="orderInfo"
                    :is-info="isInfo"
                    @show="showImg"></order-data>
      </div>
      <order-account :order-info.sync="orderInfo"
                     :is-info="isInfo"
                     @show="showImg"></order-account>
    </template>
    <div v-if="!isInfo"
         class="foot">
      <template v-if="orderInfo.status == 10 || orderInfo.status == 40 || orderInfo.status == 90 || orderInfo.status == 120 || orderInfo.status == 160">
        <el-button @click="passOrder(1)"
                   type="primary"
                   plain>通过</el-button>
        <el-button @click="lastDialog = true"
                   type="danger"
                   plain>不通过</el-button>
      </template>
      <template v-if="orderInfo.status == 50 || orderInfo.status == 110 || orderInfo.status == 130 || ((orderInfo.status == 100 || orderInfo.status == 140 ) && (orderInfo.unpassType == 1 || orderInfo.unpassType == 4)) ">
        <el-button @click="passOrder(3)"
                   type="primary"
                   plain>提交</el-button>
      </template>
      <el-button @click="() => {this.$router.go(-1)}"
                 type="primary"
                 plain>取消</el-button>
    </div>
    <div v-else
         class="foot">
      <el-button @click="() => {this.$router.go(-1)}"
                 type="primary"
                 plain>确定</el-button>
    </div>
    <el-dialog title="审核失败"
               :visible.sync="lastDialog">
      <el-form size="medium"
               label-position="right"
               label-width="150px">
        <el-form-item>
          <el-row>
            <template v-if="orderInfo.status == 40">
              <el-radio v-model="unpassInfo.unpassType"
                        label=1
                        border>资料不清晰/补充材料</el-radio>
              <el-radio v-if="orderInfo.businessType < 3"
                        v-model="unpassInfo.unpassType"
                        label=2
                        border>降低贷款额度</el-radio>
            </template>
            <template v-if="orderInfo.status == 90 || orderInfo.status == 120">
              <el-radio v-model="unpassInfo.unpassType"
                        label=4
                        border>资料不清晰重新上传</el-radio>
            </template>
            <template v-if="orderInfo.status == 40 || orderInfo.status == 90 || orderInfo.status == 120">
              <el-radio v-model="unpassInfo.unpassType"
                        label=3
                        border>审核不通过，无法继续</el-radio>
            </template>
            <template v-if="orderInfo.status == 160">
              <el-radio v-model="unpassInfo.unpassType"
                        label=5
                        border>该车不予评估，请更换车辆</el-radio>
              <el-radio v-if="orderInfo.businessType < 3"
                        v-model="unpassInfo.unpassType"
                        label=6
                        border>建议评估价</el-radio>
            </template>
          </el-row>
        </el-form-item>
        <template v-if="unpassInfo.unpassType == 1 && orderInfo.status == 40">
          <el-form-item label="终审资料">
            <el-col :span="20">
              <el-collapse accordion>
                <el-collapse-item>
                  <template slot="title">
                    <div class="collapse-item-title"><span>主贷人材料</span></div>
                  </template>
                  <el-checkbox-group v-model="unpassInfo.unpassLastAttrs">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in productMaterial.mainLender"
                            :key="key">
                      <el-button v-if="item.dataAttrId==='add'"
                                 icon="el-icon-plus"
                                 type="primary"
                                 circle
                                 size="mini"
                                 @click="addLender('mainLender', 1)"></el-button>
                      <el-tooltip v-else
                                  effect="dark"
                                  :content="item.name"
                                  placement="top">
                        <el-checkbox :label="JSON.stringify({dataAttrId:item.dataAttrId,targetType:item.targetType})">{{ item.name }}</el-checkbox>
                      </el-tooltip>
                    </el-col>
                  </el-checkbox-group>
                  <template v-if="productMaterial.mainLender.length%6 !== 0">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in 6 - productMaterial.mainLender.length%6"
                            :key="key">
                    </el-col>
                  </template>
                </el-collapse-item>
                <el-collapse-item>
                  <template slot="title">
                    <div class="collapse-item-title"><span>配偶材料</span></div>
                  </template>
                  <el-checkbox-group v-model="unpassInfo.unpassLastAttrs">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in productMaterial.mateLender"
                            :key="key">
                      <el-button v-if="item.dataAttrId==='add'"
                                 icon="el-icon-plus"
                                 type="primary"
                                 circle
                                 size="mini"
                                 @click="addLender('mateLender', 2)"></el-button>
                      <el-tooltip v-else
                                  effect="dark"
                                  :content="item.name"
                                  placement="top">
                        <el-checkbox :label="JSON.stringify({dataAttrId:item.dataAttrId,targetType:item.targetType})">{{ item.name }}</el-checkbox>
                      </el-tooltip>
                    </el-col>
                  </el-checkbox-group>
                  <template v-if="productMaterial.mateLender.length%6 !== 0">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in 6 - productMaterial.mateLender.length%6"
                            :key="key">
                    </el-col>
                  </template>
                </el-collapse-item>
                <el-collapse-item>
                  <template slot="title">
                    <div class="collapse-item-title"><span>担保人材料</span></div>
                  </template>
                  <el-checkbox-group v-model="unpassInfo.unpassLastAttrs">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in productMaterial.guarantorLender"
                            :key="key">
                      <el-button v-if="item.dataAttrId==='add'"
                                 icon="el-icon-plus"
                                 type="primary"
                                 circle
                                 size="mini"
                                 @click="addLender('guarantorLender', 3)"></el-button>
                      <el-tooltip v-else
                                  effect="dark"
                                  :content="item.name"
                                  placement="top">
                        <el-checkbox :label="JSON.stringify({dataAttrId:item.dataAttrId,targetType:item.targetType})">{{ item.name }}</el-checkbox>
                      </el-tooltip>
                    </el-col>
                  </el-checkbox-group>
                  <template v-if="productMaterial.guarantorLender.length%6 !== 0">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in 6 - productMaterial.guarantorLender.length%6"
                            :key="key">
                    </el-col>
                  </template>
                </el-collapse-item>
                <el-collapse-item>
                  <template slot="title">
                    <div class="collapse-item-title"><span>担保人配偶材料</span></div>
                  </template>
                  <el-checkbox-group v-model="unpassInfo.unpassLastAttrs">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in productMaterial.guarantorMateLender"
                            :key="key">
                      <el-button v-if="item.dataAttrId==='add'"
                                 icon="el-icon-plus"
                                 type="primary"
                                 circle
                                 size="mini"
                                 @click="addLender('guarantorMateLender', 4)"></el-button>
                      <el-tooltip v-else
                                  effect="dark"
                                  :content="item.name"
                                  placement="top">
                        <el-checkbox :label="JSON.stringify({dataAttrId:item.dataAttrId,targetType:item.targetType})">{{ item.name }}</el-checkbox>
                      </el-tooltip>
                    </el-col>
                  </el-checkbox-group>
                  <template v-if="productMaterial.guarantorMateLender.length%6 !== 0">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in 6 - productMaterial.guarantorMateLender.length%6"
                            :key="key">
                    </el-col>
                  </template>
                </el-collapse-item>
                <el-collapse-item>
                  <template slot="title">
                    <div class="collapse-item-title"><span>车辆材料</span></div>
                  </template>
                  <el-checkbox-group v-model="unpassInfo.unpassLastAttrs">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in productMaterial.carLender"
                            :key="key">
                      <el-button v-if="item.dataAttrId==='add'"
                                 icon="el-icon-plus"
                                 type="primary"
                                 circle
                                 size="mini"
                                 @click="addLender('carLender', 9)"></el-button>
                      <el-tooltip v-else
                                  effect="dark"
                                  :content="item.name"
                                  placement="top">
                        <el-checkbox :label="JSON.stringify({dataAttrId:item.dataAttrId,targetType:item.targetType})">{{ item.name }}</el-checkbox>
                      </el-tooltip>
                    </el-col>
                  </el-checkbox-group>
                  <template v-if="productMaterial.carLender.length%6 !== 0">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in 6 - productMaterial.carLender.length%6"
                            :key="key">
                    </el-col>
                  </template>
                </el-collapse-item>
              </el-collapse>
            </el-col>
          </el-form-item>
        </template>
        <template v-if="unpassInfo.unpassType == 4 && orderInfo.status == 90 && orderInfo.businessType == 1">
          <el-form-item label="放款资料">
            <el-col>
              <el-collapse accordion>
                <el-collapse-item>
                  <template slot="title">
                    <div class="collapse-item-title"><span>放款资料</span></div>
                  </template>
                  <el-checkbox-group v-model="unpassInfo.unpassAfterLoanAttrs">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in productMaterial.afterLoanLender"
                            :key="key">
                      <el-button v-if="item.dataAttrId==='add'"
                                 icon="el-icon-plus"
                                 type="primary"
                                 circle
                                 size="mini"
                                 @click="addLender('afterLoanLender', 1)"></el-button>
                      <el-tooltip v-else
                                  effect="dark"
                                  :content="item.name"
                                  placement="top">
                        <el-checkbox :label="JSON.stringify({dataAttrId:item.dataAttrId,targetType:item.targetType})">{{ item.name }}</el-checkbox>
                      </el-tooltip>
                    </el-col>
                  </el-checkbox-group>
                  <template v-if="productMaterial.afterLoanLender.length%6 !== 0">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in 6 - productMaterial.afterLoanLender.length%6"
                            :key="key">
                    </el-col>
                  </template>
                </el-collapse-item>
              </el-collapse>
            </el-col>
          </el-form-item>
        </template>
        <template v-if="unpassInfo.unpassType == 4 && orderInfo.status == 90 && orderInfo.businessType == 2">
          <el-form-item label="放款资料">
            <el-col>
              <el-collapse accordion>
                <el-collapse-item>
                  <template slot="title">
                    <div class="collapse-item-title"><span>放款资料</span></div>
                  </template>
                  <el-checkbox-group v-model="unpassInfo.unpassAfterLoanAttrs">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in productMaterial.secondAfterLoanLender"
                            :key="key">
                      <el-button v-if="item.dataAttrId==='add'"
                                 icon="el-icon-plus"
                                 type="primary"
                                 circle
                                 size="mini"
                                 @click="addLender('secondAfterLoanLender', 1)"></el-button>
                      <el-tooltip v-else
                                  effect="dark"
                                  :content="item.name"
                                  placement="top">
                        <el-checkbox :label="JSON.stringify({dataAttrId:item.dataAttrId,targetType:item.targetType})">{{ item.name }}</el-checkbox>
                      </el-tooltip>
                    </el-col>
                  </el-checkbox-group>
                  <template v-if="productMaterial.secondAfterLoanLender.length%6 !== 0">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in 6 - productMaterial.secondAfterLoanLender.length%6"
                            :key="key">
                    </el-col>
                  </template>
                </el-collapse-item>
              </el-collapse>
            </el-col>
          </el-form-item>
        </template>
        <template v-if="(orderInfo.status == 120 || (orderInfo.status == 90 && orderInfo.sufProcessType == 2)) && unpassInfo.unpassType == 4">
          <el-form-item label="抵押材料">
            <el-col>
              <el-collapse accordion>
                <el-collapse-item>
                  <template slot="title">
                    <div class="collapse-item-title"><span>抵押材料</span></div>
                  </template>
                  <el-checkbox-group v-model="unpassInfo.unpassMortgageAttrs">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in productMaterial.mortgageLender"
                            :key="key">
                      <el-button v-if="item.dataAttrId==='add'"
                                 icon="el-icon-plus"
                                 type="primary"
                                 circle
                                 size="mini"
                                 @click="addLender('mortgageLender', 1)"></el-button>
                      <el-tooltip v-else
                                  effect="dark"
                                  :content="item.name"
                                  placement="top">
                        <el-checkbox :label="JSON.stringify({dataAttrId:item.dataAttrId,targetType:item.targetType})">{{ item.name }}</el-checkbox>
                      </el-tooltip>
                    </el-col>
                  </el-checkbox-group>
                  <template v-if="productMaterial.mortgageLender.length%6 !== 0">
                    <el-col class="checkbox-item"
                            :span="4"
                            v-for="(item, key) in 6 - productMaterial.mortgageLender.length%6"
                            :key="key">
                    </el-col>
                  </template>
                </el-collapse-item>
              </el-collapse>
            </el-col>
          </el-form-item>
        </template>
        <template v-if="unpassInfo.unpassType == 2 && orderInfo.status == 40">
          <el-form-item label="车辆贷款"
                        required>
            <el-col :span="7">
              <el-input v-model.number="unpassInfo.loan"
                        size="medium">
                <template slot="append">元</template>
              </el-input>
            </el-col>
          </el-form-item>
        </template>
        <template v-if="unpassInfo.unpassType == 6 && orderInfo.status == 160">
          <el-form-item label="评估销售价"
                        required>
            <el-col :span="7">
              <el-input v-model.number="unpassInfo.assessSalesPrice"
                        size="medium">
                <template slot="append">元</template>
              </el-input>
            </el-col>
          </el-form-item>
        </template>
        <el-form-item v-if="unpassInfo.unpassType && unpassInfo.unpassType != 3 "
                      label="备注"
                      required>
          <el-col :span="15">
            <el-input type="textarea"
                      maxlength="50"
                      v-model="unpassInfo.unpassRemarks"
                      placeholder="50字以内"></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <div class="foot">
        <el-button @click="unpassOrder(2)"
                   type="primary">确认</el-button>
        <el-button @click="lastDialog = false"
                   plain>取消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="新增材料"
               :visible.sync="lenderDialog">
      <el-checkbox-group v-model="newLenderPool.lenderCheckedList"
                         @change="lenderChecked=false">
        <el-tabs tab-position="left"
                 type="border-card"
                 style="height: 500px;">
          <el-tab-pane label="文本">
            <el-col :span="12"
                    v-for="(item, key) in newLenderPool.textLenders"
                    :key="key"
                    class="add-lender-item">
              <el-col :span="1">
                <el-checkbox :label="item.key"
                             :checked="lenderChecked"
                             @change="lenderChecked=!lenderChecked"
                             class="add-lender-checkbox"></el-checkbox>
              </el-col>
              <el-col :span="10">
                <el-input v-model="item.attrName"
                          :disabled="item.cantEdit"
                          size="mini">
                </el-input>
              </el-col>
            </el-col>
            <el-col :span="12"
                    class="add-lender-item">
              <el-button @click="pushLenderPool('textLenders', 4)"
                         size="mini"
                         type="primary">新增</el-button>
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="图片">
            <el-col :span="12"
                    v-for="(item, key) in newLenderPool.picLenders"
                    :key="key"
                    class="add-lender-item">
              <el-col :span="1"
                      class="fix-down">
                <el-checkbox :label="item.key"
                             :checked="lenderChecked"
                             @change="lenderChecked=!lenderChecked"
                             class="add-lender-checkbox"></el-checkbox>
              </el-col>
              <el-col :span="10"
                      class="fix-down">
                <el-input v-model="item.attrName"
                          :disabled="item.cantEdit"
                          size="mini">
                </el-input>
              </el-col>
              <el-col :span="12"
                      :push="1"
                      class="fix-upload">
                <pic-view :pic-url-list.sync="item.examplePicUrl"
                          upload-class="short-upload"
                          :pic-name-list.sync="item.examplePicNameList"
                          :upload-data="{ picName: item.key }"
                          :upload-type="item.cantEdit"
                          @showImg="showImg"></pic-view>
              </el-col>
            </el-col>
            <el-col :span="12"
                    class="add-lender-item">
              <el-button @click="pushLenderPool('picLenders', 3)"
                         size="mini"
                         type="primary"
                         class="fix-down">新增</el-button>
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="视频">
            <el-col :span="12"
                    v-for="(item, key) in newLenderPool.videoLenders"
                    :key="key"
                    class="add-lender-item">
              <el-col :span="1">
                <el-checkbox :label="item.key"
                             :checked="lenderChecked"
                             @change="lenderChecked=!lenderChecked"
                             class="add-lender-checkbox"></el-checkbox>
              </el-col>
              <el-col :span="10">
                <el-input v-model="item.attrName"
                          :disabled="item.cantEdit"
                          size="mini">
                </el-input>
              </el-col>
            </el-col>
            <el-col :span="12"
                    class="add-lender-item">
              <el-button @click="pushLenderPool('videoLenders', 7)"
                         size="mini"
                         type="primary">新增</el-button>
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="文件">
            <el-col :span="12"
                    v-for="(item, key) in newLenderPool.fileLenders"
                    :key="key"
                    class="add-lender-item">
              <el-col :span="1">
                <el-checkbox :label="item.key"
                             :checked="lenderChecked"
                             @change="lenderChecked=!lenderChecked"
                             class="add-lender-checkbox">item.key</el-checkbox>
              </el-col>
              <el-col :span="10">
                <el-input v-model="item.attrName"
                          :disabled="item.cantEdit"
                          size="mini">
                </el-input>
              </el-col>
            </el-col>
            <el-col :span="12"
                    class="add-lender-item">
              <el-button @click="pushLenderPool('fileLenders', 6)"
                         size="mini"
                         type="primary">新增</el-button>
            </el-col>
          </el-tab-pane>
        </el-tabs>
      </el-checkbox-group>
      <div class="foot">
        <el-button @click="buildLender"
                   type="primary">确认</el-button>
        <el-button @click="lenderDialog = false"
                   plain>取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style lang="scss">
</style>

<script>
import '@/style/info.scss'
import '@/style/common.scss'
import picView from '@/components/pic-viewer-up'
import orderBase from '@/components/order-base/base'
import orderData from '@/components/order-base/data'
import fastLoan from '@/components/order-base/fastLoan'
import orderAccount from '@/components/order-base/account'
import vViewer from '@/components/v-viewer'
import viewPage from '@/components/pagination'
import filePicUp from '@/components/file-pic-up'
import { HTTPSUCCESS, HTTPDATAFAIL, HTTPPARAMFAIL, HTTPUNKOWNFAIL } from '@/components/constant'
import { api } from '@/api'
import { joinArray, checkDisabled } from '@/utils/tool'
import { material } from '@/utils/data'
import { devBaseURL } from '@/utils/http'
import { packageImgList } from '@/utils/imgPackage'
import { validatenull, vListLength } from '@/utils/validate'
import { getToken } from '@/utils/auth'

export default {
  data() {
    return {
      lenderChecked: false,
      lenderDialog: false,
      lastDialog: false,
      productMaterial: material,
      uploadAction: devBaseURL + 'sys/supplier/upload',
      isInfo: this.infoFlag === '1',
      currentPage: 1,
      total: 100,
      orderInfo: {
        contractFileList: []
      },
      unpassInfo: {
        unpassLastAttrs: [],
        unpassAfterLoanAttrs: [],
        unpassMortgageAttrs: []
      },
      firstInfo: null,
      assessInfo: null,
      lastInfo: null,
      loanAfterInfo: null,
      mortgageInfo: null,
      newLenderPool: {
        lastIndex: 0,
        lenderCheckedList: [],
        textLenders: [],
        picLenders: [],
        videoLenders: [],
        fileLenders: []
      }
    }
  },
  components: {
    picView, vViewer, viewPage, filePicUp, orderBase, orderData, fastLoan, orderAccount
  },
  props: [
    'orderId', 'infoFlag'
  ],
  activated() {
    this.getOrderCustomerInfo()
  },
  computed: {
  },
  methods: {
    getToken,
    checkDisabled,
    addLender(parentKey, targetType) {
      this.orderInfo._targetType = targetType
      this.orderInfo._parentKey = parentKey
      this.$http.get(api.SYS_PRODUCT_NEW_LENDER_POOL).then(
        res => {
          if (res.code === HTTPSUCCESS) {
            this.newLenderPool = res.data
            this.newLenderPool.lenderCheckedList = []
            this.lenderDialog = true
          } else {
            this.$msg._message('请联系系统管理员', 'error')
          }
        }
      )
    },
    buildLender() {
      let newLenders = [
        ...this.newLenderPool.textLenders,
        ...this.newLenderPool.picLenders,
        ...this.newLenderPool.videoLenders,
        ...this.newLenderPool.fileLenders]
      newLenders.map(
        e => {
          if (e.examplePicUrl) delete e['examplePicUrl']
          if (e && e.attrName != null) return e
        })
      this.newLenderPool.lenderCheckedList.forEach(
        lender => {
          newLenders = newLenders.map(
            e => {
              if (e.key === lender) { e.selected = true }
              return e
            }
          )
        }
      )
      const params = {
        newLenderPool: newLenders
      }
      this.$http.post(api.SYS_PRODUCT_NEW_LENDER, params).then(
        res => {
          if (res.code === HTTPSUCCESS) {
            this.$msg._message('新增材料成功！', 'success')
            this.fileAllList = res.data.fileAllList
            this.videoAllList = res.data.videoAllList
            const lastPool = res.data.lastPool
            lastPool.forEach(
              ele => {
                if (ele.selected) {
                  this.productMaterial[this.orderInfo._parentKey].splice(this.productMaterial[this.orderInfo._parentKey].length - 1, 0, { dataAttrId: ele.dataAttrId, name: ele.attrName, targetType: this.orderInfo._targetType })
                }
              }
            )
            this.lenderDialog = false
          } else {
            this.$msg._message('请联系系统管理员', 'error')
          }
        }
      )
    },
    pushLenderPool(poolKey, type) {
      const newKey = ++this.newLenderPool.lastIndex
      this.newLenderPool[poolKey].push({ key: 'value' + newKey, type: type })
    },
    getOrderCustomerInfo() {
      this.$http._get(api.SYS_ORDER_CUSTOMER_INFO, this.orderId).then(
        res => {
          this.firstInfo = res.data.firstInfo
          this.assessInfo = res.data.assessInfo
          this.lastInfo = res.data.lastInfo
          this.loanAfterInfo = res.data.loanAfterInfo
          this.mortgageInfo = res.data.mortgageInfo
          this.orderInfo = res.data.orderDetail
        }
      )
    },
    passOrder(status) {
      if (this.orderInfo.status === 40 && this.orderInfo.businessType < 3 && (this.loanAfterInfo && this.loanAfterInfo.some(a => a.attrId === 28))) {
        if (validatenull(this.orderInfo.contractFile)) return this.$msg._message('请上传合同模板', 'warning')
        if (this.orderInfo.contractFileLoop && this.orderInfo.contractFileLoop.some(a => (vListLength(a.names) && !validatenull(a.display)) || (!vListLength(a.names) && validatenull(a.display)))) return this.$msg._message('示例和描述需要填写完整！', 'warning')
      }
      const dataList = [...this.firstInfo, ...this.assessInfo, ...this.lastInfo, ...this.loanAfterInfo, ...this.mortgageInfo]
      dataList.map(
        e => {
          if ((e.type !== 4 || e.type !== 5) && e.objValue) {
            e.orderData = joinArray(e.objValue.names)
            delete e['objValue']
          }
        }
      )
      const accounts = JSON.parse(JSON.stringify(this.orderInfo.accounts))
      accounts.map(e => {
        if (e.idCard) {
          e.idCardFront = e.idCard.names[0]
          e.idCardBack = e.idCard.names[1]
          delete e['idCard']
        }
      })
      const params = {
        orderId: this.orderId,
        productId: this.orderInfo.productId,
        customerId: this.orderInfo.customerId,
        status: status,
        productOrderDesc: joinArray(this.orderInfo.productOrder.names),
        receivables: joinArray(this.orderInfo.receivables.names),
        accountList: accounts,
        contractFile: this.orderInfo.contractFile,
        contractExamples: !validatenull(this.orderInfo.contractFileLoop) ? joinArray(this.orderInfo.contractFileLoop.flatMap(a => a['names']).filter(a => !validatenull(a))) : null,
        contractDisplays: !validatenull(this.orderInfo.contractFileLoop) ? joinArray(this.orderInfo.contractFileLoop.map(a => a.display).filter(a => !validatenull(a))) : null,
        infoFlag: 1,
        dataList: dataList
      }
      this.$http.post(api.SYS_ORDER_APPROVE, params).then(
        res => {
          if (res.code === HTTPSUCCESS) {
            this.$msg._message('审核成功', 'success')
            this.$router.push({ name: 'order' })
          } else {
            this.$msg._message(res.data.msg, 'error')
          }
        }
      )
    },
    unpassOrder(status) {
      if (this.orderInfo.status !== 10) {
        if (validatenull(this.unpassInfo.unpassType)) return this.$msg._message('请勾选不通过原因！', 'warning')
        if (this.unpassInfo.unpassType === '1' && validatenull(this.unpassInfo.unpassLastAttrs)) return this.$msg._message('请勾选需要补充或者重传的材料！', 'warning')
        if (this.unpassInfo.unpassType === '2' && validatenull(this.unpassInfo.loan)) return this.$msg._message('请填写车辆贷款！', 'warning')
        if (this.unpassInfo.unpassType === '6' && validatenull(this.unpassInfo.assessSalesPrice)) return this.$msg._message('请填写评估销售价！', 'warning')
        if (this.unpassInfo.unpassType === '4' && ((validatenull(this.unpassInfo.unpassAfterLoanAttrs) && this.orderInfo.status === 90 && this.orderInfo.sufProcessType === 1))) return this.$msg._message('请勾选需要重传的材料！', 'warning')
        if (this.unpassInfo.unpassType === '4' && (validatenull(this.unpassInfo.unpassMortgageAttrs) && this.orderInfo.status === 120)) return this.$msg._message('请勾选需要重传的材料！', 'warning')
        if (this.unpassInfo.unpassType === '4' && this.orderInfo.sufProcessType === 2 && validatenull(this.unpassInfo.unpassMortgageAttrs) && validatenull(this.unpassInfo.unpassAfterLoanAttrs)) return this.$msg._message('请勾选需要重传的材料！', 'warning')
        if (this.unpassInfo.unpassType !== '3' && validatenull(this.unpassInfo.unpassRemarks)) return this.$msg._message('请填写不通过备注！', 'warning')
      }
      const unpassInfo = JSON.parse(JSON.stringify(this.unpassInfo))
      unpassInfo.unpassLastAttrs = unpassInfo.unpassLastAttrs.map(a => JSON.parse(a))
      unpassInfo.unpassAfterLoanAttrs = unpassInfo.unpassAfterLoanAttrs.map(a => JSON.parse(a))
      unpassInfo.unpassMortgageAttrs = unpassInfo.unpassMortgageAttrs.map(a => JSON.parse(a))
      const params = {
        orderId: this.orderId,
        status: status,
        unpassInfo: unpassInfo,
        infoFlag: 0
      }
      this.$http.post(api.SYS_ORDER_APPROVE, params).then(
        res => {
          if (res.code === HTTPSUCCESS) {
            this.$msg._message('审核成功', 'success')
            this.lastDialog = false
            this.$router.push({ name: 'order' })
          } else {
            this.$msg._message(res.data.msg, 'error')
          }
        }
      )
    },
    showImg(url) {
      this.$refs.view.showImg(url)
    },
    down(step) {
      self.location.href = devBaseURL + api.SYS_ORDER_DOWNLOADZIP + '/' + this.orderId + '/normal/' + step
    }
  }
}
</script>
